$(document).ready(function() {

    //var
    var x = 10;
    var y = 30;
    var toolTip_width = 200;

    $(".toolTip").hover(function(e) {
        this.toolTip_text = this.title;
        this.title = "";
        if (this.toolTip_text) {
            var t = "<p>" + this.toolTip_text + "</p>";
        }
        else {
            var t = "";
        }
        if (this.rel) {
            $("body").append("<div id='toolTip'><img src='" + this.rel + "' alt='img preview' />" + t + "</div>");
        }
        else {

            $("body").append("<div id='toolTip'>" + t + "</div>");
        }
        $("#toolTip").css("top", (e.pageY - x) + "px").css("left", (e.pageX + y) + "px").css("-moz-border-radius", "5px").fadeIn("fast");
    }, function() {
        this.title = this.toolTip_text;
        $("#toolTip").remove();
    });
    $(".toolTip").mousemove(function(e) {
        $("#toolTip").css("top", (e.pageY - x) + "px").css("left", (e.pageX + y) + "px");
    });

   

    //var
    var hoverColor = "#005b7f";
    var normalColor = "#88ddff";

    $("ul#menu li a").before("<span></span>");
    $("ul#menu a").not(".active").prev().css("opacity", "0");
    $("ul#menu a.active").attr({
        href: "#"
    }).css({
        "cursor": "default",
        "color": hoverColor
    });
    $("ul#menu a").not(".active").hover(function() {
        $(this).prev().stop().animate({
            opacity: 1
        }, "slow");
        $(this).stop().animate({
            "color": hoverColor
        }, "slow");
    }, function() {
        $(this).prev().stop().animate({
            opacity: 0
        }, "slow");
        $(this).stop().animate({
            "color": normalColor
        }, "slow");

    });

    //RSS
    $("div#rss a").before("<div></div>");
    $("div#rss a").prev().css("opacity", "0");
    $("div#rss a").hover(function() {
        $(this).prev().stop().animate({
            opacity: 1
        }, "slow");
    }, function() {
        $(this).prev().stop().animate({
            opacity: 0
        }, "slow");
    });

    //UP
    $("div#up a").before("<div></div>");
    $("div#up a").prev().css("opacity", "0");
    $("div#up a").hover(function() {
        $(this).prev().stop().animate({
            opacity: 1
        }, "slow");
    }, function() {
        $(this).prev().stop().animate({
            opacity: 0
        }, "slow");
    });

    $("div#up a").click(function(e) {
        e.preventDefault();
        var target = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
        target.animate({
            scrollTop: $($(this).attr("href")).offset().top
        }, 500);
    });


   


    //var
    var message_ok = "Thank you!";
    var message_error = "Can't send email!";
    var sending = "sending please wait..."

    var num_input = $("div.rascals_form").size();

    //newsletter 
    var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var newsletter = $(".newsletter").val();
    $("#emailNews").focus(function() {
        var current_newsletter = $(this).val();
        if (newsletter == current_newsletter || current_newsletter == message_ok || current_newsletter == message_error) {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val(newsletter);
        }
    });


    $("#emailNews").keyup(function() {
        if ($(this).val().match(email)) {
            var newsletter_send = $(this).val();
            $(".newsletter-submit").fadeIn("slow").click(function() {
                $(".newsletter-submit").unbind("click")
                $("#emailNews").val(sending);
                $.post("newsletter.ashx", {
                    newsletter: newsletter_send
                }, function(data) {
                  
                    if (data == 'error') {
                        $(".newsletter-submit").fadeOut("slow");
                        $("#emailNews").val(message_error);

                    }
                    else {
                        $(".newsletter-submit").fadeOut("slow");
                        $("#emailNews").val(message_ok);
                    }
                });
            });
        }
        else {
            $(".newsletter-submit").fadeOut("slow");
        }

    });



    function check() {
        if ($("div.rascals_form").find("span.active").size() == num_input) {
            $("#send").fadeIn("slow").click(function() {
                $("#send").unbind("click");
                $(this).fadeOut("slow");
                $("div.rascals_form_submit span").text(sending).fadeIn("slow");
                var form_name = $("#name").val();
                var form_email = $("#email").val();
                var form_message = $("#message").val();
                $("#name, #email, #message").val("");
                $("div.rascals_form span").removeClass("active").fadeOut("slow");
                $.post("newsletter.ashx", {
                    name: form_name,
                    email: form_email,
                    message: form_message
                }, function(data) {
                    if (data == 'error') {
                        $("div.rascals_form_submit span").text(message_error).fadeIn("slow");
                    }
                    else {
                        $("div.rascals_form_submit span").text(message_ok).fadeOut(5000);
                    }
                });

            })
        }
        else {
            $("#send").fadeOut("slow");
        }
    }


    $("#name").keyup(function() {
        if ($(this).val().length > 2) {
            $(this).next().addClass("active").fadeIn("slow");
            check();
        }
        else {
            $(this).next().removeClass("active").fadeOut("slow");
            check();
        }
    });
    $("#email").keyup(function() {
        if ($(this).val().match(email)) {
            $(this).next().addClass("active").fadeIn("slow")
            check();
        }
        else {
            $(this).next().removeClass("active").fadeOut("slow");
            check();
        }
    });
    $("#message").keyup(function() {
        if ($(this).val().length > 2) {
            $(this).next().addClass("active").fadeIn("slow")
            check();
        }
        else {
            $(this).next().removeClass("active").fadeOut("slow");
            check();
        }
    });


    //SIDEBAR

    var sidebar_length = $("div.sidebar").size();

    for (i = 0; i < sidebar_length; i++) {
        var cookie_name = $("div.sidebar:eq(" + i + ")").attr("id");
        var cookie_value = $.cookie(cookie_name);
        $("div#" + cookie_value + "").find("h3").addClass("active").next("div").css("display", "block");
    }

    $("div.sidebar h3").click(function() {
        if ($(this).is(".active")) {

            $.cookie($(this).parent().attr("id"), null);
            $(this).removeClass("active").next("div").slideUp("normal");
        }
        else {

            $.cookie($(this).parent().attr("id"), $(this).parent().attr("id"));
            $(this).addClass("active").next("div").slideDown("normal");

        }

    });
    //collapse all
    $("span#collapse-all").click(function() {
        if ($("div.sidebar h3").is(".active")) {
            $("div.sidebar h3").removeClass("active").next("div").slideUp("normal");
            for (i = 0; i < sidebar_length; i++) {
                var cookie_name = $("div.sidebar:eq(" + i + ")").attr("id");
                var cookie_value = $.cookie(cookie_name, null);
            }

        }

    });
    $("span#expand-all").click(function() {
        if ($("div.sidebar h3").not(".active")) {
            $("div.sidebar h3").addClass("active").next("div").slideDown("normal");
            for (i = 0; i < sidebar_length; i++) {
                var cookie_name = $("div.sidebar:eq(" + i + ")").attr("id");
                var cookie_value = $.cookie(cookie_name, cookie_name);
            }
        }

    });

})

; (function($) {
    /**
    * Cookie plugin
    *
    * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
    * Dual licensed under the MIT and GPL licenses:
    * http://www.opensource.org/licenses/mit-license.php
    * http://www.gnu.org/licenses/gpl.html
    *
    */

    /**
    * Create a cookie with the given name and value and other optional parameters.
    *
    * @example $.cookie('the_cookie', 'the_value');
    * @desc Set the value of a cookie.
    * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
    * @desc Create a cookie with all available options.
    * @example $.cookie('the_cookie', 'the_value');
    * @desc Create a session cookie.
    * @example $.cookie('the_cookie', null);
    * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
    *       used when the cookie was set.
    *
    * @param String name The name of the cookie.
    * @param String value The value of the cookie.
    * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
    * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
    *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
    *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
    *                             when the the browser exits.
    * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
    * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
    * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
    *                        require a secure protocol (like HTTPS).
    * @type undefined
    *
    * @name $.cookie
    * @cat Plugins/Cookie
    * @author Klaus Hartl/klaus.hartl@stilbuero.de
    */

    /**
    * Get the value of a cookie with the given name.
    *
    * @example $.cookie('the_cookie');
    * @desc Get the value of a cookie.
    *
    * @param String name The name of the cookie.
    * @return The value of the cookie.
    * @type String
    *
    * @name $.cookie
    * @cat Plugins/Cookie
    * @author Klaus Hartl/klaus.hartl@stilbuero.de
    */
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // NOTE Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };

})(jQuery);

/*
* jQuery Color Animations
* Copyright 2007 John Resig
* Released under the MIT and GPL licenses.
*/

(function(jQuery) {

    // We override the animation for all of these color styles
    jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'],
function(i, attr) {
    jQuery.fx.step[attr] = function(fx) {
        if (fx.state == 0) {
            fx.start = getColor(fx.elem, attr);
            fx.end = getRGB(fx.end);
        }
        try { //Added 2010-02-05 by Rickard Magnusson, Enterprisesoft.se : causes IE to crash
            fx.elem.style[attr] = "rgb(" + [
			        Math.max(Math.min(parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
			        Math.max(Math.min(parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
			        Math.max(Math.min(parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
		        ].join(",") + ")";
        } catch (fx) { };
    }
});

    // Color Conversion functions from highlightFade
    // By Blair Mitchelmore
    // http://jquery.offput.ca/highlightFade/

    // Parse strings looking for color tuples [255,255,255]
    function getRGB(color) {
        var result;

        // Check if we're already dealing with an array of colors
        if (color && color.constructor == Array && color.length == 3)
            return color;

        // Look for rgb(num,num,num)
        if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
            return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

        // Look for rgb(num%,num%,num%)
        if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
            return [parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55];

        // Look for #a0b1c2
        if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
            return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)];

        // Look for #fff
        if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
            return [parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16)];

        // Otherwise, we're most likely dealing with a named color
        return colors[jQuery.trim(color).toLowerCase()];
    }

    function getColor(elem, attr) {
        var color;

        do {
            color = jQuery.curCSS(elem, attr);

            // Keep going until we find an element that has color, or we hit the body
            if (color != '' && color != 'transparent' || jQuery.nodeName(elem, "body"))
                break;

            attr = "backgroundColor";
        } while (elem = elem.parentNode);

        return getRGB(color);
    };

    // Some named colors to work with
    // From Interface by Stefan Petre
    // http://interface.eyecon.ro/

    var colors = {
        aqua: [0, 255, 255],
        azure: [240, 255, 255],
        beige: [245, 245, 220],
        black: [0, 0, 0],
        blue: [0, 0, 255],
        brown: [165, 42, 42],
        cyan: [0, 255, 255],
        darkblue: [0, 0, 139],
        darkcyan: [0, 139, 139],
        darkgrey: [169, 169, 169],
        darkgreen: [0, 100, 0],
        darkkhaki: [189, 183, 107],
        darkmagenta: [139, 0, 139],
        darkolivegreen: [85, 107, 47],
        darkorange: [255, 140, 0],
        darkorchid: [153, 50, 204],
        darkred: [139, 0, 0],
        darksalmon: [233, 150, 122],
        darkviolet: [148, 0, 211],
        fuchsia: [255, 0, 255],
        gold: [255, 215, 0],
        green: [0, 128, 0],
        indigo: [75, 0, 130],
        khaki: [240, 230, 140],
        lightblue: [173, 216, 230],
        lightcyan: [224, 255, 255],
        lightgreen: [144, 238, 144],
        lightgrey: [211, 211, 211],
        lightpink: [255, 182, 193],
        lightyellow: [255, 255, 224],
        lime: [0, 255, 0],
        magenta: [255, 0, 255],
        maroon: [128, 0, 0],
        navy: [0, 0, 128],
        olive: [128, 128, 0],
        orange: [255, 165, 0],
        pink: [255, 192, 203],
        purple: [128, 0, 128],
        violet: [128, 0, 128],
        red: [255, 0, 0],
        silver: [192, 192, 192],
        white: [255, 255, 255],
        yellow: [255, 255, 0]
    };

})(jQuery);

